Skip to content

Avoid redundant dynamic_pointer_cast in YogaLayoutableShadowNode clone (#57019)#57019

Closed
javache wants to merge 1 commit into
facebook:mainfrom
javache:export-D106287171
Closed

Avoid redundant dynamic_pointer_cast in YogaLayoutableShadowNode clone (#57019)#57019
javache wants to merge 1 commit into
facebook:mainfrom
javache:export-D106287171

Conversation

@javache
Copy link
Copy Markdown
Member

@javache javache commented Jun 1, 2026

Summary:

The clone constructor of YogaLayoutableShadowNode rebuilt the
internal yogaLayoutableChildren_ vector on every clone by
walking every child with dynamic_pointer_cast. When the cloned
node inherits its children list from the source (!fragment.children)
the result is identical to the source's vector, so copy it directly
instead — no RTTI required.

Also reserve() the vector to its upper bound at the top of
updateYogaChildren() so the rebuild on the new-children path no
longer reallocates as it grows.

Both changes are pure CPU-time optimizations on a hot path that
shows up heavily in animation-driven tree clones; behaviour is
unchanged.

Changelog:
[Internal]

Reviewed By: christophpurrer, lenaic

Differential Revision: D106287171

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 1, 2026
@facebook-github-tools facebook-github-tools Bot added p: Facebook Partner: Facebook Partner labels Jun 1, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Jun 1, 2026

@javache has exported this pull request. If you are a Meta employee, you can view the originating Diff in D106287171.

@meta-codesync meta-codesync Bot changed the title Avoid redundant dynamic_pointer_cast in YogaLayoutableShadowNode clone Avoid redundant dynamic_pointer_cast in YogaLayoutableShadowNode clone (#57019) Jun 2, 2026
javache added a commit to javache/react-native that referenced this pull request Jun 2, 2026
facebook#57019)

Summary:

The clone constructor of `YogaLayoutableShadowNode` rebuilt the
internal `yogaLayoutableChildren_` vector on every clone by
walking every child with `dynamic_pointer_cast`. When the cloned
node inherits its children list from the source (`!fragment.children`)
the result is identical to the source's vector, so copy it directly
instead — no RTTI required.

Also `reserve()` the vector to its upper bound at the top of
`updateYogaChildren()` so the rebuild on the new-children path no
longer reallocates as it grows.

Both changes are pure CPU-time optimizations on a hot path that
shows up heavily in animation-driven tree clones; behaviour is
unchanged.

Changelog:
[Internal]

Reviewed By: christophpurrer, lenaic

Differential Revision: D106287171
@javache javache force-pushed the export-D106287171 branch from 5be76c0 to c96be7d Compare June 2, 2026 12:24
javache added a commit to javache/react-native that referenced this pull request Jun 3, 2026
facebook#57019)

Summary:

The clone constructor of `YogaLayoutableShadowNode` rebuilt the
internal `yogaLayoutableChildren_` vector on every clone by
walking every child with `dynamic_pointer_cast`. When the cloned
node inherits its children list from the source (`!fragment.children`)
the result is identical to the source's vector, so copy it directly
instead — no RTTI required.

Also `reserve()` the vector to its upper bound at the top of
`updateYogaChildren()` so the rebuild on the new-children path no
longer reallocates as it grows.

Both changes are pure CPU-time optimizations on a hot path that
shows up heavily in animation-driven tree clones; behaviour is
unchanged.

Changelog:
[Internal]

Reviewed By: christophpurrer, lenaic

Differential Revision: D106287171
facebook#57019)

Summary:

The clone constructor of `YogaLayoutableShadowNode` rebuilt the
internal `yogaLayoutableChildren_` vector on every clone by
walking every child with `dynamic_pointer_cast`. When the cloned
node inherits its children list from the source (`!fragment.children`)
the result is identical to the source's vector, so copy it directly
instead — no RTTI required.

Also `reserve()` the vector to its upper bound at the top of
`updateYogaChildren()` so the rebuild on the new-children path no
longer reallocates as it grows.

Both changes are pure CPU-time optimizations on a hot path that
shows up heavily in animation-driven tree clones; behaviour is
unchanged.

Changelog:
[Internal]

Reviewed By: christophpurrer, lenaic

Differential Revision: D106287171
@javache javache force-pushed the export-D106287171 branch from c96be7d to 644b5a5 Compare June 3, 2026 13:08
@meta-codesync meta-codesync Bot closed this in 4bf3477 Jun 3, 2026
@facebook-github-tools facebook-github-tools Bot added the Merged This PR has been merged. label Jun 3, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Jun 3, 2026

This pull request has been merged in 4bf3477.

@react-native-bot
Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @javache in 4bf3477

When will my fix make it into a release? | How to file a pick request?

@javache javache deleted the export-D106287171 branch June 3, 2026 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants